/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef COLORABSTRACT_H_
#define COLORABSTRACT_H_

#include <string>
#include <iostream>
#include "../EnumAbstract.h"

template<template<typename> class Color, typename Int>
class ColorAbstract : public EnumAbstract<Color<Int>, Int> {
public:
	static const Int COUNT = 3;
	static const Color<Int> WHITE();
	static const Color<Int> BLACK();
public:
	static const Color<Int> BEGIN() { return Color<Int>::WHITE(); }
	static const Color<Int> RBEGIN() { return Color<Int>::BLACK(); }
public:

	bool isWhite() const { return this->me_c() == Color<Int>::WHITE(); }
	bool isBlack() const { return this->me_c() == Color<Int>::BLACK(); }

	Color<Int> rival() const {
		return Color<Int>(this->me_c().isWhite() ? Color<Int>::BLACK() : Color<Int>::WHITE());
	}

	void setRival();

	std::string toStr() const {
		std::string ret;
		if      ( this->me_c().isWhite() ) ret = "w";
		else if ( this->me_c().isBlack() ) ret = "b";
		else                               ret = "-";

		return ret;
	}

	void fromStr(const std::string str) {
		if      ( "w" == str ) this->me() = Color<Int>::WHITE();
		else if ( "b" == str ) this->me() = Color<Int>::BLACK();
		else                   this->me() = Color<Int>::NIL();
	}
};

#endif /* COLORABSTRACT_H_ */
